package com.dlb.andorid.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dlb.andorid.R;
import com.dlb.andorid.XContract;
import com.dlb.andorid.bean.UserAccount;
import com.dlb.andorid.presenter.MxPresenter;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseCommonActivity;

import java.util.ArrayList;
import java.util.List;

public class MxActivity extends BaseCommonActivity implements XContract.IMxView {

	MxPresenter mPresenter;

	@Override
	protected BasePresenter getBasePresenter() {
		mPresenter = new MxPresenter(this);
		return mPresenter;
	}

	@Override
	protected void initData() {
		showProgress("");
		mPresenter.getMxList();
	}

	@Override
	protected int getTopViewId() {
		return 0;
	}

	@Override
	protected int getMainViewId() {
		return R.layout.activity_mx;
	}

	@Override
	protected int getBottomViewId() {
		return 0;
	}

	@Override
	protected String getTitleTxt() {
		return "账户明细";
	}

	@Override
	public String getPageName() {
		return null;
	}

	RecyclerView recycleView;
	BaseQuickAdapter<UserAccount, BaseViewHolder> mAdapter;
	ArrayList<UserAccount> mAccounts = new ArrayList<>();

	@Override
	protected void initViews() {
		super.initViews();
		recycleView = findViewById(R.id.recycleView);
		mAdapter = new BaseQuickAdapter<UserAccount, BaseViewHolder>(R.layout.layout_list_item_mx, mAccounts) {
			@Override
			protected void convert(BaseViewHolder helper, UserAccount item) {

				helper.setText(R.id.tv_title,item.getType_name());
				helper.setText(R.id.tv_time,item.getAddtime());
				helper.setText(R.id.tv_num,item.getAdd_sub()+" "+item.getInfo());



			}
		};
		recycleView.setLayoutManager(new LinearLayoutManager(this));
		recycleView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		recycleView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
		recycleView.setHasFixedSize(true);
		//解决更新 闪烁
		recycleView.setItemAnimator(null);
		recycleView.setNestedScrollingEnabled(false);
		recycleView.setAdapter(mAdapter);
	}


	@Override
	public void getMxListSuccess(List<UserAccount> data) {
		mAccounts.clear();
		mAccounts.addAll(data);
		mAdapter.setNewData(mAccounts);
	}
}
